
project , uses("constituency_elections.dta")
project , uses("candidate_elections.dta")


	**Summary Statistics
	
	quietly {
		cap log close
		set linesize 255
		log using ./tables/summary_statistics.tex, text replace
		noisily dis "\begin{table}[htbp]"
		noisily dis "\begin{center}"
		noisily dis "\caption{ {\bf Descriptive Statistics \label{tab:stats}} }"
	*	noisily display "  }"
		noisily dis " \begin{adjustbox}{max width=0.9\textwidth} "
		noisily dis "\begin{tabular}{l rrrrrr}"
		noisily dis "\toprule \toprule"
		noisily dis " & Mean & St. Dev. & Skew.& Min. & Max. & Obs. \\"
		noisily dis "\midrule"

		*constituency level
		use constituency_elections.dta, clear
		replace spending_limit_predicted_adj  = 10000*spending_limit_predicted_adj
		label var electors "Electors"
		label var county "County Constituency"
		label var spending_ads "Spending on Advertisement"
		label var spending_meetings "Spending on Meetings"
		label var spending_staff "Spending on Staff"
		label var spending_facilities "Spending on Facilities"
		label var spending_misc "Spending on Miscellaneous"
		label var spending_managers "Spending on Agents"
		label var spending_personal "Personal Spending"
		label var spending_limit_predicted_adj "Spending Limit"
		label var spending_total_adj "Spending Total"
		label var inc_vote_pct "Incumbent Vote \%"
		label var inc_spending_pct "Incumbent Spending \%"			
		
		noisily dis "\\ & \multicolumn{6}{c}{Constituency Level} \\"
		noisily dis " \cmidrule(lr){2-7} "		
			
		foreach var in spending_limit_predicted_adj spending_total_adj electors candidates effective_candidates effective_spenders county inc_vote_pct inc_spending_pct spending_managers_adj spending_staff_adj spending_ads_adj spending_meetings_adj spending_facilities_adj spending_misc_adj spending_personal_adj {
		
		
				local varlab : variable label `var'	
				qui sum `var', d
				local mean = r(mean)
				local sd = r(sd)
				local skew = r(skewness)
				local min = r(min)
				local max = r(max)
				local obs = r(N)
				noisily dis " `varlab' & " %9.1fc  `mean' " & "  %9.1fc  `sd' " & " %9.1fc  `skew' " & " %9.1fc `min' " & " %9.1fc `max' " & " %9.0fc `obs' " \\"
		}
		
		
		noisily dis "\\ & \multicolumn{6}{c}{Candidate Level} \\"
		noisily dis " \cmidrule(lr){2-7} "		
		
		
		*candidate level
		use "candidate_elections.dta", clear //open data
		replace spending_limit_predicted_adj  = 10000*spending_limit_predicted_adj		
		label var spending_limit_predicted_adj "Spending Limit"
		label var spending_total_adj "Spending Total"
		label var spending_pct "Spending \%"
		label var vote_pct "Vote \%"
		label var inc "Incumbent"
		label var spending_limit_predicted_adj "Spending Limit"
		label var lab "Labour Party"
		label var lib "Liberal (Dem.) Party"
		label var other "Other Party"
		
		foreach var in spending_limit_predicted_adj spending_total_adj vote_pct spending_pct   inc { 
				local varlab : variable label `var'	
				qui sum `var', d
				local mean = r(mean)
				local sd = r(sd)
				local skew = r(skewness)
				local min = r(min)
				local max = r(max)
				local obs = r(N)
				noisily dis " `varlab' & " %9.1fc  `mean' " & "  %9.1fc  `sd' " & " %9.1fc  `skew' " & " %9.1fc `min' " & " %9.1fc `max' " & " %9.0fc `obs' " \\"
		}		
		
	
		*/
		noisily dis "\bottomrule \bottomrule"
		noisily dis "\end{tabular}"
		noisily dis "\end{adjustbox}"
		noisily dis "\end{center}"	
		noisily dis " \footnotesize{ \textsc{Note:} In the constituency-level panel, each observation pertains to constituency in "
		noisily dis " a given election. In the candidate-level panel, each observation pertains to a candidate in a given election. "
		noisily dis " All monetary values are adjusted for inflation and reported in 2020 prices.} "

		noisily dis "\end{table}"
		
		log off
	}

	
	
	
	
	
* changes in spending limits
	
	
	quietly {
		cap log close
		set linesize 255
		log using ./tables/spending_limit_changes.tex, text replace
		noisily dis "\begin{table}[htbp]"
		noisily dis "\begin{center}"
		noisily dis "\caption{ {\bf Changes in Spending Limits in Counties and Boroughs in Reform Years\label{tab:limit_change}} }"
		noisily dis " \begin{adjustbox}{max width=0.75\textwidth} "
		noisily dis "\begin{tabular}{l rrrr rrrr}"
		noisily dis "\toprule \toprule"
		
		noisily dis "\\ Reform & \multicolumn{4}{c}{Counties} & \multicolumn{4}{c}{Boroughs} \\"

		noisily dis " Year & Mean & St. Dev. & Min & Max & Mean & St. Dev. & Min & Max \\"
		
		noisily dis " \cmidrule(lr){2-5} \cmidrule(lr){6-9}  "		
		

		*constituency level
		use candidate_elections.dta, clear
		replace spending_limit_predicted_adj = 10000*spending_limit_predicted_adj
		drop if by==1
		collapse (mean) spending_limit_predicted_adj,by(const county date year)
		drop if date==date("10oct1974", "DMY")
		sort const date
		bys const: gen limit_change = spending_limit_predicted_adj - spending_limit_predicted_adj[_n-1]	
		
		foreach y in 1918 1929 1950 1970 1974 1979 1983 1987 1992 1997 2001 2005 2015 {
			sum limit_change if year==`y' & county==1
			local mean_county = r(mean)
			local sd_county = r(sd)
			local min_county = r(min)
			local max_county = r(max)
			
			sum limit_change if year==`y' & county==0
			local mean_borough = r(mean)
			local sd_borough = r(sd)
			local min_borough = r(min)
			local max_borough = r(max)

			noisily dis " `y' & " %10.1fc  `mean_county' " & " %10.1fc  `sd_county'  " & " %10.1fc  `min_county' " & " %10.1fc  `max_county' "  & "  %10.1fc  `mean_borough' "  & "  %10.1fc  `sd_borough'   " & " %10.1fc  `min_borough' " & " %10.1fc  `max_borough' " \\"	


			}		
		
		
		noisily dis "\bottomrule \bottomrule"
		noisily dis "\end{tabular}"
		noisily dis "\end{adjustbox}"
		noisily dis "\end{center}"	
		*noisily dis " \footnotesize{ \textsc{Note:} } "

		noisily dis "\end{table}"
		
		log off
	}
			
	
	
	project , creates("tables/summary_statistics.tex")	
	project , creates("tables/spending_limit_changes.tex")	


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
